<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>JavaScript的标识符 |  zfy的个人博客</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="./img/Scorpio.png">
    <link rel="stylesheet" href="./css/style.css">
    <meta name="description" content="My tech blog">
    
    <link rel="preload" href="./assets/css/0.styles.cfdaa54c.css" as="style"><link rel="preload" href="./assets/js/app.7878252f.js" as="script"><link rel="preload" href="./assets/js/2.877879cc.js" as="script"><link rel="preload" href="./assets/js/41.23b0f26d.js" as="script"><link rel="prefetch" href="./assets/js/10.a489e96f.js"><link rel="prefetch" href="./assets/js/11.f6f26a2f.js"><link rel="prefetch" href="./assets/js/12.8a827e29.js"><link rel="prefetch" href="./assets/js/13.e420b04a.js"><link rel="prefetch" href="./assets/js/14.52f00cc6.js"><link rel="prefetch" href="./assets/js/15.ef68d553.js"><link rel="prefetch" href="./assets/js/16.c2999dfd.js"><link rel="prefetch" href="./assets/js/17.0adb748c.js"><link rel="prefetch" href="./assets/js/18.2c077020.js"><link rel="prefetch" href="./assets/js/19.013b5e02.js"><link rel="prefetch" href="./assets/js/20.bb3b854e.js"><link rel="prefetch" href="./assets/js/21.28efc78c.js"><link rel="prefetch" href="./assets/js/22.4a1d71dd.js"><link rel="prefetch" href="./assets/js/23.605a5451.js"><link rel="prefetch" href="./assets/js/24.66bf035d.js"><link rel="prefetch" href="./assets/js/25.fbe72655.js"><link rel="prefetch" href="./assets/js/26.3f374d1f.js"><link rel="prefetch" href="./assets/js/27.556ea617.js"><link rel="prefetch" href="./assets/js/28.0cab868b.js"><link rel="prefetch" href="./assets/js/29.564f8747.js"><link rel="prefetch" href="./assets/js/3.4cfb1b9c.js"><link rel="prefetch" href="./assets/js/30.c4a099d1.js"><link rel="prefetch" href="./assets/js/31.7fbc3d2a.js"><link rel="prefetch" href="./assets/js/32.8f356b20.js"><link rel="prefetch" href="./assets/js/33.b5a1b0bb.js"><link rel="prefetch" href="./assets/js/34.57086c2e.js"><link rel="prefetch" href="./assets/js/35.2b4d0231.js"><link rel="prefetch" href="./assets/js/36.a99f6d64.js"><link rel="prefetch" href="./assets/js/37.eb25dcef.js"><link rel="prefetch" href="./assets/js/38.e45d8594.js"><link rel="prefetch" href="./assets/js/39.213e3a72.js"><link rel="prefetch" href="./assets/js/4.b86a0fbe.js"><link rel="prefetch" href="./assets/js/40.cadafdd6.js"><link rel="prefetch" href="./assets/js/42.7c2b83c6.js"><link rel="prefetch" href="./assets/js/43.62f328ea.js"><link rel="prefetch" href="./assets/js/44.c4dfbd34.js"><link rel="prefetch" href="./assets/js/45.cde5bb22.js"><link rel="prefetch" href="./assets/js/46.6c62bdb8.js"><link rel="prefetch" href="./assets/js/47.4857766a.js"><link rel="prefetch" href="./assets/js/48.55a0cccc.js"><link rel="prefetch" href="./assets/js/49.3dceda91.js"><link rel="prefetch" href="./assets/js/5.13776f82.js"><link rel="prefetch" href="./assets/js/50.ab4d52fa.js"><link rel="prefetch" href="./assets/js/51.69ccc35a.js"><link rel="prefetch" href="./assets/js/52.01f3f711.js"><link rel="prefetch" href="./assets/js/53.c146a1ff.js"><link rel="prefetch" href="./assets/js/54.71ce70c2.js"><link rel="prefetch" href="./assets/js/55.98ef481d.js"><link rel="prefetch" href="./assets/js/56.b23daa51.js"><link rel="prefetch" href="./assets/js/57.6aa314ad.js"><link rel="prefetch" href="./assets/js/58.7d6367d9.js"><link rel="prefetch" href="./assets/js/59.88894cf5.js"><link rel="prefetch" href="./assets/js/6.93d89692.js"><link rel="prefetch" href="./assets/js/60.111f9a04.js"><link rel="prefetch" href="./assets/js/61.add82aab.js"><link rel="prefetch" href="./assets/js/62.8bfac830.js"><link rel="prefetch" href="./assets/js/63.db44a5ca.js"><link rel="prefetch" href="./assets/js/64.0244f0ef.js"><link rel="prefetch" href="./assets/js/65.2be994de.js"><link rel="prefetch" href="./assets/js/66.c5066e37.js"><link rel="prefetch" href="./assets/js/67.c11b474b.js"><link rel="prefetch" href="./assets/js/68.276bdc3e.js"><link rel="prefetch" href="./assets/js/69.f5f39d50.js"><link rel="prefetch" href="./assets/js/7.ca9f7e96.js"><link rel="prefetch" href="./assets/js/70.e3ca02b0.js"><link rel="prefetch" href="./assets/js/71.befcf8f7.js"><link rel="prefetch" href="./assets/js/72.04fabafd.js"><link rel="prefetch" href="./assets/js/73.e5b707f2.js"><link rel="prefetch" href="./assets/js/74.b5668150.js"><link rel="prefetch" href="./assets/js/75.eb7cfac9.js"><link rel="prefetch" href="./assets/js/76.c1b76370.js"><link rel="prefetch" href="./assets/js/77.5875e953.js"><link rel="prefetch" href="./assets/js/78.a5e2fa5b.js"><link rel="prefetch" href="./assets/js/79.eb2d51a7.js"><link rel="prefetch" href="./assets/js/8.570c39ea.js"><link rel="prefetch" href="./assets/js/80.7252ac50.js"><link rel="prefetch" href="./assets/js/81.eb980d26.js"><link rel="prefetch" href="./assets/js/82.9e069d8f.js"><link rel="prefetch" href="./assets/js/83.8c5a6dc6.js"><link rel="prefetch" href="./assets/js/84.26baaa09.js"><link rel="prefetch" href="./assets/js/85.96bc7e77.js"><link rel="prefetch" href="./assets/js/86.9c9dd1ca.js"><link rel="prefetch" href="./assets/js/87.d54639b8.js"><link rel="prefetch" href="./assets/js/88.3d3ae1e1.js"><link rel="prefetch" href="./assets/js/89.a81caa83.js"><link rel="prefetch" href="./assets/js/9.7a58df3d.js"><link rel="prefetch" href="./assets/js/90.c3c347ed.js"><link rel="prefetch" href="./assets/js/91.b6240032.js"><link rel="prefetch" href="./assets/js/92.8331718a.js"><link rel="prefetch" href="./assets/js/93.ca174cfa.js"><link rel="prefetch" href="./assets/js/94.fec3300c.js"><link rel="prefetch" href="./assets/js/95.076b06fb.js"><link rel="prefetch" href="./assets/js/96.8ed8b32f.js">
    <link rel="stylesheet" href="./assets/css/0.styles.cfdaa54c.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/./" class="home-link router-link-active"><!----> <span class="site-name"> zfy的个人博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="http://127.0.0.1:3002/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  自由博客板块
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="http://zfyangelo.gitee.io/yu-weather-web-show/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  天气预报
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="/./guide/" class="nav-link router-link-active">
  个人的学习笔记
</a></div><div class="nav-item"><a href="/./baodian/interview/" class="nav-link">
  项目及在校经历
</a></div><div class="nav-item"><a href="/./baodian/talk/" class="nav-link">
  爱好和联系方式
</a></div><div class="nav-item"><a href="https://gitee.com/zfyangelo" target="_blank" rel="noopener noreferrer" class="nav-link external">
  我的gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="http://127.0.0.1:3002/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  自由博客板块
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="http://zfyangelo.gitee.io/yu-weather-web-show/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  天气预报
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="/./guide/" class="nav-link router-link-active">
  个人的学习笔记
</a></div><div class="nav-item"><a href="/./baodian/interview/" class="nav-link">
  项目及在校经历
</a></div><div class="nav-item"><a href="/./baodian/talk/" class="nav-link">
  爱好和联系方式
</a></div><div class="nav-item"><a href="https://gitee.com/zfyangelo" target="_blank" rel="noopener noreferrer" class="nav-link external">
  我的gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>HTML</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>CSS</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Javascipt</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/./guide/notes/js/01-认识javaScript.html" class="sidebar-link">01-认识javaScript</a></li><li><a href="/./guide/notes/js/02-变量与数据类型介绍.html" class="active sidebar-link">02-变量与数据类型介绍</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/./guide/notes/js/02-变量与数据类型介绍.html#javascript的标识符" class="sidebar-link">JavaScript的标识符</a></li><li class="sidebar-sub-header"><a href="/./guide/notes/js/02-变量与数据类型介绍.html#什么是变量" class="sidebar-link">什么是变量?</a></li><li class="sidebar-sub-header"><a href="/./guide/notes/js/02-变量与数据类型介绍.html#变量命名规范" class="sidebar-link">变量命名规范</a></li><li class="sidebar-sub-header"><a href="/./guide/notes/js/02-变量与数据类型介绍.html#数据类型" class="sidebar-link">数据类型</a></li><li class="sidebar-sub-header"><a href="/./guide/notes/js/02-变量与数据类型介绍.html#typeof-操作符" class="sidebar-link">typeof 操作符</a></li><li class="sidebar-sub-header"><a href="/./guide/notes/js/02-变量与数据类型介绍.html#赋值和取值" class="sidebar-link">赋值和取值</a></li></ul></li><li><a href="/./guide/notes/js/03-基础dom操作.html" class="sidebar-link">03-基础dom操作</a></li><li><a href="/./guide/notes/js/04-表达式和操作符.html" class="sidebar-link">04-表达式和操作符</a></li><li><a href="/./guide/notes/js/05-判断.html" class="sidebar-link">05-判断</a></li><li><a href="/./guide/notes/js/06-循环.html" class="sidebar-link">06-循环</a></li><li><a href="/./guide/notes/js/07-算法拓展.html" class="sidebar-link">07-算法拓展</a></li><li><a href="/./guide/notes/js/08-函数.html" class="sidebar-link">08-函数</a></li><li><a href="/./guide/notes/js/09-作用域,闭包,预解析.html" class="sidebar-link">09-作用域,闭包,预解析</a></li><li><a href="/./guide/notes/js/10-数组.html" class="sidebar-link">10-数组</a></li><li><a href="/./guide/notes/js/11-字符串.html" class="sidebar-link">11-字符串</a></li><li><a href="/./guide/notes/js/12-类型转换.html" class="sidebar-link">12-类型转换</a></li><li><a href="/./guide/notes/js/13-DOM进阶.html" class="sidebar-link">13-DOM进阶</a></li><li><a href="/./guide/notes/js/14-dom事件与机制.html" class="sidebar-link">14-dom事件与机制</a></li><li><a href="/./guide/notes/js/15-浏览器M操作.html" class="sidebar-link">15-浏览器M操作</a></li><li><a href="/./guide/notes/js/16-toProject.html" class="sidebar-link">16-toProject</a></li><li><a href="/./guide/notes/js/17-内置数学和时间project.html" class="sidebar-link">17-内置数学和时间project</a></li><li><a href="/./guide/notes/js/18-各种距离宽高获取.html" class="sidebar-link">18-各种距离宽高获取</a></li><li><a href="/./guide/notes/js/19-正则表达式.html" class="sidebar-link">19-正则表达式</a></li><li><a href="/./guide/notes/js/21-箭头函数.html" class="sidebar-link">20箭头函数</a></li><li><a href="/./guide/notes/js/22-解构赋值.html" class="sidebar-link">21-解构赋值</a></li><li><a href="/./guide/notes/js/23-project字面量增强和函数默认参数.html" class="sidebar-link">22-project字面量增强和函数默认参数</a></li><li><a href="/./guide/notes/js/24-剩余参数和展开运算符.html" class="sidebar-link">23-剩余参数和展开运算符</a></li><li><a href="/./guide/notes/js/25-Set 和 Map数据结构和Symbol.html" class="sidebar-link">24-Set 和 Map数据结构和Symbol</a></li><li><a href="/./guide/notes/js/26-遍历器和for-of循环.html" class="sidebar-link">25-遍历器和for-of循环</a></li><li><a href="/./guide/notes/js/27-Promise.html" class="sidebar-link">26-Promise</a></li><li><a href="/./guide/notes/js/28-Clsss类.html" class="sidebar-link">27-Clsss类</a></li><li><a href="/./guide/notes/js/29-module模块.html" class="sidebar-link">28-module模块</a></li><li><a href="/./guide/notes/js/30-Babel.html" class="sidebar-link">29-Babel</a></li><li><a href="/./guide/notes/js/31-前后端通信和HTTP协议.html" class="sidebar-link">30-前后端通信和HTTP协议</a></li><li><a href="/./guide/notes/js/32-本地存储.html" class="sidebar-link">31-本地存储</a></li><li><a href="/./guide/notes/js/33-ajax.html" class="sidebar-link">32-ajax</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>HTML&amp;CSS练习</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Javascipt练习</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h2 id="javascript的标识符"><a href="#javascript的标识符" class="header-anchor">#</a> JavaScript的标识符</h2> <h4 id="_1、什么是标识符"><a href="#_1、什么是标识符" class="header-anchor">#</a> 1、什么是标识符?</h4> <blockquote><p>变量、函数、属性的名字，或者函数的参数。</p></blockquote> <h4 id="_2、标识符的命名规则"><a href="#_2、标识符的命名规则" class="header-anchor">#</a> 2、标识符的命名规则:</h4> <blockquote><p>(1)、由字母、数字、下划线(_ )或美元符号( $ )组成</p> <p>(2)、不能以数字开头</p> <p>(3)、不能使用关键字、保留字等作为标识符</p></blockquote> <h2 id="什么是变量"><a href="#什么是变量" class="header-anchor">#</a> 什么是变量?</h2> <blockquote><p>ECMAScript的变量是松散类型</p> <p>松散类型:可以用来保存任何类型的数据</p> <p>换句话说,每个变量仅仅是一个用于保存值的占位符而已</p></blockquote> <h2 id="变量命名规范"><a href="#变量命名规范" class="header-anchor">#</a> 变量命名规范</h2> <blockquote><p>1.只允许使用 数字、字母、下划线、$ (不能使用数字开头)</p> <p>2.严格区分大小写</p> <p>3.不要重复定义/声明</p> <p>4.<strong>关键词/保留词</strong>  不能用来做变量名</p> <p>5.语义化驼峰命名</p> <p>6.见名知意</p></blockquote> <ol><li><strong>关键字</strong>    =&gt;     js已经赋予特殊功能的单词</li> <li><strong>保留字</strong>     =&gt;    js预订可能未来要使用的字</li></ol> <p><strong>关键字:</strong></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code>break、else、new、var、 case、 finally 、 return、 void 、 catch 、for 、switch 、 while 、 continue、 function 、this 、 with 、default 、 if 、 throw 、 delete 、 in 、 try 、do 、 instranceof、 typeof
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>保留字:</strong></p> <div class="language-css line-numbers-mode"><pre class="language-css"><code>abstract 、 enum 、int 、 short 、 boolean 、export 、interface、 static、 byte 、extends 、 long 、 super 、 char 、 final 、native 、synchronized 、 class 、float 、 package 、throws 、 const 、goto 、private 、transient 、 debugger 、 implements 、protected 、 volatile 、 double 、import 、public
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//以下都是合法的变量名</span>

<span class="token keyword">let</span> a<span class="token punctuation">;</span>
<span class="token keyword">let</span> <span class="token constant">A</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> b333<span class="token punctuation">;</span>
<span class="token keyword">let</span> _abc<span class="token punctuation">;</span>
<span class="token keyword">let</span> $<span class="token punctuation">;</span>
<span class="token keyword">let</span> $o0_0o$<span class="token punctuation">;</span>
<span class="token keyword">let</span> ________<span class="token punctuation">;</span>
<span class="token keyword">let</span> _<span class="token punctuation">;</span>

<span class="token comment">// 以下都是非法的变量名</span>
<span class="token keyword">let</span> 123a<span class="token punctuation">;</span>
<span class="token keyword">let</span> 12_a<span class="token punctuation">;</span>
<span class="token keyword">let</span> abc@<span class="token number">163</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> abc￥<span class="token punctuation">;</span>
<span class="token keyword">let</span> <span class="token keyword">let</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> <span class="token keyword">class</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><p><strong>注意:</strong></p> <blockquote><p>关键字,保留字不用可以的去记忆, 在未来学习的过程中会接触到一大部分关键字保留字,</p></blockquote> <h3 id="定义变量的多个写法"><a href="#定义变量的多个写法" class="header-anchor">#</a> 定义变量的多个写法</h3> <blockquote><p>使用 let 关键字定义一个变量</p> <p>同一个变量不能多次定义（ES6中使用 let 多次定义同一个变量直接报错）</p></blockquote> <h4 id="_1-定义时赋值-常用"><a href="#_1-定义时赋值-常用" class="header-anchor">#</a> 1.定义时赋值(常用)</h4> <blockquote><p>赋值运算符  变量的赋值用等号，等号就是赋值符号，在JS中等号没有其他的含义，等号就表示赋值。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> x <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>  <span class="token comment">//变量可以理解为一个容器，用来存储一个值。</span>
		 	<span class="token comment">//上面先声明变量a，然后在变量a与数值10之间建立引用关系，称为将数值1&quot;赋值&quot;给变量a</span>
<span class="token keyword">let</span> y <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span> <span class="token comment">//JavaScript 的变量名区分大小写，x和X是两个不同的变量。</span>


<span class="token comment">//=  两边的空格不是必须的 为了美观</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h4 id="_2-先定义后赋值"><a href="#_2-先定义后赋值" class="header-anchor">#</a> 2.先定义后赋值</h4> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> x<span class="token punctuation">;</span>
<span class="token keyword">let</span> y<span class="token punctuation">;</span>
x <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
y <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h4 id="_3-同时定义多个变量-用逗号隔开"><a href="#_3-同时定义多个变量-用逗号隔开" class="header-anchor">#</a> 3.同时定义多个变量,用逗号隔开</h4> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> x<span class="token punctuation">,</span>y<span class="token punctuation">;</span>
x <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
y <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>

<span class="token comment">//等价于 </span>
<span class="token keyword">let</span> x <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">,</span>
 	y <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p><strong>注意</strong></p> <blockquote><p>如果变量赋值的时候，忘了写 let 命令，这条语句也是有效的。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>

<span class="token comment">// 基本等同</span>

a <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token comment">//省略声明的变量是全局变量  不推荐省略let操作符来定义全局变量 建议总是使用let命令声明变量</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>如果<strong>一个变量没有声明就直接使用</strong>，JavaScript 会报错，告诉你变量未定义。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// ReferenceError: x is not defined</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h4 id="_4-定义常量"><a href="#_4-定义常量" class="header-anchor">#</a> 4.定义常量</h4> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> x <span class="token operator">=</span> <span class="token number">3.1315927</span><span class="token punctuation">;</span>

<span class="token comment">//const 定义的变量称之为常量,是不允许重新赋值的.</span>

<span class="token comment">//开发约定俗成 常量名字全大写</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>注意 ：</strong></p> <blockquote><p>= 左边为一个变量，不能为表达式</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> b <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span> 
<span class="token keyword">let</span> c<span class="token punctuation">;</span>
a <span class="token operator">-</span> c <span class="token operator">=</span> b   <span class="token comment">// 报错 ，赋值运算符左边不能为表达式</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>    
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="语句"><a href="#语句" class="header-anchor">#</a> 语句</h3> <blockquote><p>JavaScript 程序的执行单位为行，一行一行地执行，一般情况，一行就是一个语句。</p> <p>语句是为了完成某种任务而进行的操作。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token number">1</span> <span class="token operator">+</span> <span class="token number">3</span><span class="token punctuation">;</span>
<span class="token comment">//这条语句先用let命令，声明了变量a，然后将1 + 3的运算结果赋值给变量a</span>
<span class="token comment">//1 + 3叫做表达式(expression),指一个为了得到返回值的计算式。</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div></blockquote> <p><strong>语句和表达式的区别</strong></p> <blockquote><p>语句主要为了进行某种操作，一般情况下不需要返回值</p> <p>表达式则是为了得到返回值，一定会返回一个值。 JavaScript 语言中预期为值的地方，都可以使用表达式。</p> <p>将同类型的数据(如常量、变量、函数等) , 用运算符号按一定的规则连接起来的、有意义的式子称为表达式</p> <p>比如，赋值语句的等号右边，预期是一个值，因此可以放置各种表达式。</p></blockquote> <p><strong>JavaScript 是一种动态类型语言</strong>，也就是说，变量的类型没有限制，变量可以随时更改类型。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>
a <span class="token operator">=</span> <span class="token string">&quot;云牧牧&quot;</span><span class="token punctuation">;</span>
<span class="token comment">//上面代码中  变量a先被赋值为一个数值   又被重新赋值为一个字符串</span>
<span class="token comment">//第二次赋值的时候    因为变量a已经存在    不需要使用var命令</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><strong>区分变量还是直接量</strong></p> <blockquote><p>变量的时候，不能加引号。如果变量加上引号，就变成字符串的直接量了。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token number">200</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&quot;a&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment">//a</span>

<span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token string">&quot;大家好&quot;</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>	<span class="token comment">//大家好</span>

<span class="token comment">//引号是“字符串”的定界符，所以在双引号里面的a已经失去了变量的意思，就是一个字符串a。</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="数据类型"><a href="#数据类型" class="header-anchor">#</a> 数据类型</h2> <blockquote><p>在一门语言里，会存在各种各样的值。</p> <p>各种各种的数据都是用来解决不同的应用场景的需求。</p></blockquote> <p><strong>基本类型：</strong></p> <blockquote><p>number 数值</p> <p>string 字符串</p> <p>boolean 布尔值</p> <p>undefined 未定义</p> <p>null 空指针</p></blockquote> <p><strong>复杂数据类型：</strong></p> <blockquote><p>object  对象</p></blockquote> <p><strong>ES6新增</strong></p> <blockquote><p>symbol 唯一值</p> <p>bigint 大整数</p></blockquote> <h3 id="string"><a href="#string" class="header-anchor">#</a> String</h3> <p><strong>基本介绍</strong></p> <blockquote><p>字符串是由0或是多个字符组成的字符序列,即字符串;</p> <p>字符串是一个术语，说白了就是我们人说的话。</p> <p>字符串可以用双引号(“”)或是单引号(‘’)或模板字符串(``)包裹起来,</p> <p>三除外观上没有任何的不同,可随意使用</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code> <span class="token keyword">let</span> b <span class="token operator">=</span> <span class="token string">&quot;云牧&quot;</span><span class="token punctuation">;</span><span class="token comment">//双引号</span>
 <span class="token keyword">let</span> bb <span class="token operator">=</span> <span class="token string">'薛宝钗'</span><span class="token punctuation">;</span><span class="token comment">//单引号</span>
 <span class="token keyword">let</span> bbb <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">林黛玉</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span><span class="token comment">//模板字符串</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>如果一个数字，用引号引起来，那么就是字符串了。</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&quot;666&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>不加引号是错误的</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//  不能不加引号，这是错误的：</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>云牧帅<span class="token constant">B</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>注意引号必须是同种引号,混用错误</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>'嘻嘻&quot;<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>正常情况</strong></p> <blockquote><p>引号内部可以有不同种的引号，比如双引号里面可以有单引号：</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 双引号中用单引号</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&quot;你笑起来像'花儿'一样好看&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 单引号中用双引号</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'你笑起来像&quot;花儿&quot;一样好看'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><strong>如果要在双引号里使用双引号或者单引号内使用单引号</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> b1 <span class="token operator">=</span> <span class="token string">&quot;云\&quot;\&quot;牧&quot;</span><span class="token punctuation">;</span>
<span class="token comment">//使用\进行转义  将有意义的符号转为没有意义的字符</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>可以将没有意义的字面<code>n</code>转为有意义的换行</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//转义字符</span>
<span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">&quot;你们\n啊\n怎么可以\n那么可爱呢&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="boolean"><a href="#boolean" class="header-anchor">#</a> boolean</h3> <blockquote><p>布尔（逻辑）只能有两个值：true 或 false。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> c <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span> <span class="token comment">// true</span>
<span class="token keyword">let</span> c <span class="token operator">=</span> <span class="token boolean">false</span> <span class="token comment">//false</span>
        
        
<span class="token keyword">let</span> d <span class="token operator">=</span> <span class="token number">20</span> <span class="token operator">&gt;</span> <span class="token number">30</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//false</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>如果 JavaScript <strong>预期</strong>某个位置应该是<strong>布尔值</strong>，会将该<strong>位置</strong>上现有的值<strong>自动转为布尔值</strong>。</p> <p><strong>除了下面六个值被转为<code>false</code>，其他值都视为<code>true</code>。</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">undefined</span>
<span class="token keyword">null</span>
<span class="token boolean">false</span>
<span class="token number">0</span>
<span class="token number">NaN</span>
<span class="token string">&quot;&quot;</span>或<span class="token string">''</span>或 <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token template-punctuation string">`</span></span>（空字符串）
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token string">&quot;0&quot;</span><span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token string">&quot; &quot;</span><span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true  空字符串中带空格也为true</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token string">&quot;false&quot;</span><span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token string">&quot;null&quot;</span><span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">Boolean</span><span class="token punctuation">(</span><span class="token number">2</span> <span class="token operator">-</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//false</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>布尔值往往用于程序流程的控制</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'true'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">//if命令后面的判断条件，预期应该是一个布尔值  JavaScript 自动将空字符串，转为布尔值false</span>
<span class="token comment">//导致程序不会进入代码块，所以没有任何输出。</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="number"><a href="#number" class="header-anchor">#</a> Number</h3> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>

<span class="token keyword">let</span> aa <span class="token operator">=</span> <span class="token number">10</span> <span class="token operator">+</span> <span class="token number">20</span><span class="token punctuation">;</span>	<span class="token comment">//右边为表达式 运算整体赋值给aa变量</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h5 id="整数"><a href="#整数" class="header-anchor">#</a> 整数</h5> <blockquote><p>JavaScript中，数字的整数字面量可以有三种进制：</p> <p>10进制： 普通的数字就是十进制</p> <p>8进制：如果以0、0o、0O开头数字字面量是八进制，八进制只包括数字0~7</p> <p>16进制：如果以0x,0X开头数字字面量是十六进制。十六进制整数可以包含(0-9)和字母 a-f 或 A-F</p></blockquote> <h6 id="二进制"><a href="#二进制" class="header-anchor">#</a> 二进制</h6> <blockquote><p>二进制数值以0b,0B开头</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token number">0b10</span> <span class="token comment">//2</span>
<span class="token number">0b1111</span> <span class="token comment">//15</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h6 id="八进制"><a href="#八进制" class="header-anchor">#</a> 八进制</h6> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//以0开头，是八进制；显示的时候会以十进制显示</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">017</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//15  //7*8的零次方  +  1*8的一次方 </span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">0o17</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">//15</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">0O17</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">//15</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">044</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//4*8的零次方 + 4*8的一次方</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">010</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">//8</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">0o36</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//30</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">0O36</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//30</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><strong>注意</strong></p> <blockquote><p>八进制只能出现0~7这8中数字，如果表示不合法，那么JS将自动的认为你输入错了，从而用十进制进行显示：</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">080</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//80 </span>
<span class="token comment">//以0开头，按理说是八进制，但是后面的数字错了，所以以十进制显示</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>但是以0o开头、0O开头的数字，如果后面写错了，控制台报错！</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 如果是0o开头的，后面的数字错了，对不起，不转为10进制了，控制台报错！</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>0o88<span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">//报错</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>0O88<span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">//报错</span>

<span class="token comment">//// 控制台报错  语法错误</span>
<span class="token comment">//Uncaught SyntaxError: Invalid or unexpected token</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h6 id="十六进制"><a href="#十六进制" class="header-anchor">#</a> 十六进制</h6> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 十六进制：</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">0xff</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">//255   f相当于15</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">0x2b</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">//43  </span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>如果后面有错误的写法，那么控制台报错</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>0x2g<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 控制台报错   语法错误</span>
<span class="token comment">//Uncaught SyntaxError: Invalid or unexpected token</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h5 id="浮点数"><a href="#浮点数" class="header-anchor">#</a> 浮点数</h5> <blockquote><p><strong>JavaScript 内部，所有数字都是以64位浮点数形式储存</strong></p> <p>小数或指数</p> <p>计算机世界中，小数称为“浮点数”</p> <p>指数就是:允许使用e来表示乘以10的几次幂</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">3.1415</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">.35</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//0.35 如果整数位数是0，可以不写</span>


console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">5e5</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//500000</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">5.2e5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//520000</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">1e-4</span><span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment">//0.0001</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p><strong>注意:</strong></p> <blockquote><p>只有十进制有小数的字面量，八进制、十六进制没有小数的字面量。所以小数没有进制之分</p></blockquote> <p>由于<strong>浮点数不是精确的值</strong>，所以涉及小数的比较和运算要特别小心</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">0.1</span><span class="token operator">+</span><span class="token number">0.2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//0.30000000000000004	</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span> <span class="token punctuation">(</span><span class="token number">0.3</span><span class="token operator">-</span><span class="token number">0.2</span><span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token punctuation">(</span><span class="token number">0.2</span><span class="token operator">-</span><span class="token number">0.1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// false</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h5 id="infinity"><a href="#infinity" class="header-anchor">#</a> Infinity</h5> <blockquote><p><code>Infinity</code>表示“无穷”，用来表示两种场景</p> <p>一种是一个正的数值太大，或一个负的数值太小无法表示</p> <p>另一种是非0数值除以0，得到<code>Infinity</code>。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 场景一</span>
 console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span> Math<span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">1024</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//2的1024次方</span>
<span class="token comment">// Infinity  </span>
<span class="token comment">//表达式的计算结果太大太小，超出了能够表示的范围，因此返回Infinity</span>


<span class="token comment">// 场景二</span>
 console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token operator">/</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// Infinity</span>
<span class="token comment">//而非0数值除以0，会返回Infinity。</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><strong><code>Infinity</code>有正负之分，<code>Infinity</code>表示正的无穷，<code>-Infinity</code>表示负的无穷</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">Infinity</span> <span class="token operator">===</span> <span class="token operator">-</span><span class="token number">Infinity</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">1</span>  <span class="token operator">/</span> <span class="token number">0</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">//Infinity</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span>  <span class="token operator">/</span> <span class="token number">0</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// -Infinity</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span>  <span class="token operator">/</span> <span class="token operator">-</span><span class="token number">0</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Infinity</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>由于数值正向溢出（overflow）、负向溢出（underflow）和被<code>0</code>除，JavaScript 都不报错，所以单纯的数学运算几乎没有可能抛出错误。</p> <p><strong><code>Infinity</code>大于一切数值（除了<code>NaN</code>），<code>-Infinity</code>小于一切数值（除了<code>NaN</code>）。</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">Infinity</span> <span class="token operator">&gt;</span> <span class="token number">88888</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// true</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">Infinity</span> <span class="token operator">&lt;</span> <span class="token number">88888</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//true</span>

<span class="token comment">//Infinity与NaN比较，总是返回false。</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h5 id="nan"><a href="#nan" class="header-anchor">#</a> NaN</h5> <blockquote><p><code>NaN</code>是 JavaScript 的特殊值，英语全名叫做not a number，表示“非数字“</p> <p>主要出现在将字符串解析成数字出错的场合。</p> <p><strong><code>NaN</code>不等于任何值</strong>，包括<strong>它本身</strong>。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">1</span> <span class="token operator">-</span> <span class="token string">'云牧dsb'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// NaN</span>

<span class="token comment">//0除以0也会得到NaN.	</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token operator">/</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// NaN</span>
<span class="token comment">//注意的是，NaN不是独立的数据类型，而是一个特殊数值，它的数据类型依然属于Number</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h5 id="isnan"><a href="#isnan" class="header-anchor">#</a> isNaN()</h5> <blockquote><p><code>isNaN</code>方法可以用来判断一个值是否为<code>NaN</code>。</p> <p>但isNaN()也不好用，</p> <p><strong>它的机理是</strong>:只要该变量传入Number()的执行结果是NaN，则isNaN()函数都会得到true</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token number">NaN</span><span class="token punctuation">)</span>  <span class="token comment">//true</span>
<span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span>  <span class="token comment">//true</span>
<span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token keyword">undefined</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
<span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token string">'3天'</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//true</span>
<span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//false</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token number">NaN</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token number">123</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// false</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong><code>isNaN</code>只对数值有效</strong>，如果传入其他值，会先被先转成数值。</p> <p>比如，传入字符串的时候，<strong>字符串会被先转成<code>NaN</code></strong>，所以最后返回<code>true</code></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token string">'Hello'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>出于同样的原因，对于<strong>对象和数组</strong>，<code>isNaN</code>也<strong>返回<code>true</code></strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">&quot;yun&quot;</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>对于<strong>空数组和只有一个数值成员的数组</strong>，<code>isNaN</code>返回<code>false</code>。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// false</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">123</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// false</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isNaN</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">'123'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>上面代码之所以返回<code>false</code>，原因是这些数组能被<code>Number</code>函数转成数值</p> <h5 id="isfinite"><a href="#isfinite" class="header-anchor">#</a> isFinite()</h5> <blockquote><p><code>isFinite</code>方法返回一个布尔值，表示某个值是否为正常的数值。</p> <p>如果 number 是 NaN（非数字），或者是正、负无穷大的数，则返回 false。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token number">Infinity</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">Infinity</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token number">NaN</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token keyword">undefined</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// false</span>


<span class="token comment">//除了Infinity、-Infinity、NaN和undefined这几个值会返回false</span>

<span class="token comment">//isFinite对于其他的数值都会返回true。</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">isFinite</span><span class="token punctuation">(</span><span class="token number">666</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h3 id="undefined"><a href="#undefined" class="header-anchor">#</a> Undefined</h3> <blockquote><p>undefined 表示这个值未被定义</p></blockquote> <p><strong>undefined 出现的场景：</strong></p> <blockquote><p>（1）变量被声明了，但没有赋值时，就等于undefined。</p> <p><strong>下面3条先不讲</strong></p> <p>（2)   调用函数时，应该提供的参数没有提供，该参数等于undefined。</p> <p>（3）对象没有赋值的属性，该属性的值为undefined。</p> <p>（4）函数没有返回值时，默认返回undefined。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> a<span class="token punctuation">;</span><span class="token comment">//未定义</span>
        
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>address<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//表示这个变量未被赋值</span>
<span class="token keyword">let</span> address <span class="token operator">=</span> <span class="token keyword">undefined</span><span class="token punctuation">;</span> <span class="token comment">//很少使用</span>

<span class="token comment">//提前定义变量,不清楚数据类型,后续赋值。</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="null"><a href="#null" class="header-anchor">#</a> Null</h3> <blockquote><p>null 表示空，与undefined不同的是，</p> <p>null它表示一个空对象指针，undefined则表示未定义</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code> <span class="token keyword">let</span> f <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
 <span class="token comment">//提前定义变量,指向一个空的内存地址,知道这个变量即将存储对象数据。</span>

<span class="token comment">//当我们需要将对象销毁、数组销毁或者删除事件监听时，通常将它们设置为null。</span>
box<span class="token punctuation">.</span>onclick <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>如果一个需要保存对象的变量没有真正保存对象，就应该明确的让该变量保存 null 值，这样做不仅可以体现 null 作为空对象指针的惯例，而且有助于进一步区分 null 和 undefined</p> <p><strong>说明:</strong></p> <blockquote><p>undefined值是派生自null值的,所以undefined == null的返回结果是true</p></blockquote> <h3 id="object-对象数据类型"><a href="#object-对象数据类型" class="header-anchor">#</a> Object 对象数据类型</h3> <blockquote><p>对象是最复杂的数据类型，又可以分成三个子类型。</p> <ul><li><strong>狭义的对象（object）</strong></li> <li><strong>数组（array）</strong></li> <li><strong>函数（function）</strong></li></ul></blockquote> <h4 id="array-数组"><a href="#array-数组" class="header-anchor">#</a> Array 数组</h4> <blockquote><p>数组（array）是按次序排列的一组值。每个值的位置都有编号（从0开始），整个数组用方括号表示。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//数组的作用是用来存储一组数据,本身是复杂类型,里面存储其他任何类型的数据</span>

<span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token string">&quot;林黛玉&quot;</span> <span class="token punctuation">,</span><span class="token string">&quot;云牧&quot;</span> <span class="token punctuation">,</span> <span class="token string">&quot;薛宝钗&quot;</span> <span class="token punctuation">,</span> <span class="token number">200</span> <span class="token punctuation">,</span><span class="token boolean">true</span><span class="token punctuation">]</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>取值</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span> <span class="token string">&quot;下标1的数据:&quot;</span> <span class="token punctuation">,</span> a<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>


console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&quot;数组的长度&quot;</span><span class="token punctuation">,</span>  a<span class="token punctuation">.</span>length <span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//取的数组长度</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><strong>重新赋值</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>a<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span><span class="token comment">//给某一项重新赋值</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>如果在中间多写一个逗号里面什么都不写</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> b <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token string">&quot;林黛玉&quot;</span> <span class="token punctuation">,</span> <span class="token string">&quot;云牧&quot;</span> <span class="token punctuation">,</span> <span class="token punctuation">,</span> <span class="token string">&quot;薛宝钗&quot;</span> <span class="token punctuation">,</span> <span class="token number">200</span> <span class="token punctuation">,</span><span class="token boolean">true</span><span class="token punctuation">]</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span> b <span class="token punctuation">)</span><span class="token punctuation">;</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&quot;数组的长度&quot;</span><span class="token punctuation">,</span> b<span class="token punctuation">.</span>length <span class="token punctuation">)</span><span class="token punctuation">;</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span> <span class="token string">&quot;下标2的数据:&quot;</span> <span class="token punctuation">,</span> b<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//数组占位为empty , 取值是undefined的数据类型     </span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p><strong>人为设置<code>length</code>大于当前元素个数，则数组的成员数量会增加到这个值，新增的位置都是空位</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
arr<span class="token punctuation">[</span><span class="token number">10</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>   <span class="token comment">// arr[3]到arr[9] 的值为 empty (留了空位) 读取新增的位置都会返回undefined。</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">[</span><span class="token number">9</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token comment">//undefined</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>人为设置一个小于当前成员个数的值，该数组的成员数量会自动减少到<code>length</code>设置的值。</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token string">'a'</span><span class="token punctuation">,</span> <span class="token string">'b'</span><span class="token punctuation">,</span> <span class="token string">'c'</span> <span class="token punctuation">]</span><span class="token punctuation">;</span>
arr<span class="token punctuation">.</span>length <span class="token comment">// 3</span>

arr<span class="token punctuation">.</span>length <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
arr <span class="token comment">// [&quot;a&quot;, &quot;b&quot;]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>清空数组的一个有效方法，就是将<code>length</code>属性设为0。</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>arr<span class="token punctuation">.</span>length <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token comment">//[]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>除了在定义时赋值，数组也可以先定义后赋值。</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

arr<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'a'</span><span class="token punctuation">;</span>
arr<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'b'</span><span class="token punctuation">;</span>
arr<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'c'</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h5 id="数组的嵌套取值"><a href="#数组的嵌套取值" class="header-anchor">#</a> 数组的嵌套取值</h5> <blockquote><p>如果数组的元素还是数组，就形成了<strong>多维数组</strong></p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code>	<span class="token comment">// 二维数组 ---&gt; 数组里面嵌套数组</span>
        <span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token punctuation">[</span> 
            <span class="token string">&quot;林黛玉&quot;</span><span class="token punctuation">,</span>
            <span class="token string">&quot;云牧&quot;</span><span class="token punctuation">,</span> 
            <span class="token string">&quot;薛宝钗&quot;</span><span class="token punctuation">,</span>
            <span class="token number">200</span><span class="token punctuation">,</span>
            <span class="token boolean">true</span><span class="token punctuation">,</span>
            <span class="token punctuation">[</span>
                <span class="token string">&quot;绿巨人&quot;</span><span class="token punctuation">,</span>
                <span class="token string">&quot;钢铁侠&quot;</span><span class="token punctuation">,</span>
                <span class="token string">&quot;超人&quot;</span><span class="token punctuation">,</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
        <span class="token punctuation">]</span><span class="token punctuation">;</span>

 console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//超人</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h4 id="object-对象数据-狭义的对象"><a href="#object-对象数据-狭义的对象" class="header-anchor">#</a> object 对象数据(狭义的对象)</h4> <blockquote><p>Js核心概念</p> <p>对象是一组键值对的集合 , 是一种无序的复合数据集合</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code>  <span class="token comment">//对象  ---&gt;  对一个东西的描述</span>

<span class="token keyword">let</span> lindaiyu <span class="token operator">=</span> <span class="token punctuation">{</span>
    <span class="token literal-property property">name</span> <span class="token operator">:</span> <span class="token string">&quot;林黛玉小怼怼&quot;</span><span class="token punctuation">,</span>    <span class="token comment">//属性名(键名):属性值(键值)</span>
    <span class="token literal-property property">sex</span> <span class="token operator">:</span> <span class="token string">&quot;女&quot;</span><span class="token punctuation">,</span>		
    <span class="token literal-property property">age</span> <span class="token operator">:</span> <span class="token number">16</span> <span class="token punctuation">,</span>				
    <span class="token literal-property property">weight</span> <span class="token operator">:</span> <span class="token string">&quot;50kg&quot;</span><span class="token punctuation">,</span>
    <span class="token literal-property property">height</span> <span class="token operator">:</span> <span class="token string">&quot;150cm&quot;</span><span class="token punctuation">,</span>
    <span class="token literal-property property">marry</span> <span class="token operator">:</span> <span class="token boolean">false</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>lindaiyu<span class="token punctuation">)</span><span class="token punctuation">;</span>

 <span class="token comment">/*对象所有的属性名都是字符串,加引号和不加引号都可以 除非不符合标识符的规则，比如第一个字符为数字含有空格或运算符*/</span>

<span class="token comment">//属性值可以是任何数据类型</span>

<span class="token comment">//每一个属性名被称为属性,如果一个属性名的值是函数,则这个属性称为方法</span>

<span class="token comment">//属性之间用逗号分隔 , 最后一个属性可加可不加</span>

 <span class="token comment">//属性名不能相同 属性值能相同</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><p><strong>对象取值</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//取值,不通过序号下标去获取</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>lindaiyu<span class="token punctuation">.</span>name<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>lindaiyu<span class="token punctuation">.</span>age<span class="token punctuation">)</span><span class="token punctuation">;</span>


console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>lindaiyu<span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//取一个对象不存在的属性返回undefined</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><strong>对象修改</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>lindaiyu<span class="token punctuation">.</span>marry <span class="token operator">=</span> <span class="token boolean">true</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>lindaiyu<span class="token punctuation">.</span>marry<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>添加新属性</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>lindaiyu<span class="token punctuation">.</span>hobby <span class="token operator">=</span> <span class="token string">&quot;怼人&quot;</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>lindaiyu<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//属性可以动态的创建和添加 不必在对象声明时全部指定</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>对象删除</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">delete</span> lindaiyu<span class="token punctuation">.</span>age
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>lindaiyu<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// = 赋值操作不能删除对象属性</span>
lindaiyu<span class="token punctuation">.</span>height <span class="token operator">=</span> <span class="token keyword">undefined</span><span class="token punctuation">;</span>
lindaiyu<span class="token punctuation">.</span>height <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>lindaiyu<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p><strong>简单练习</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code> <span class="token keyword">let</span> lindaiyu <span class="token operator">=</span> <span class="token punctuation">{</span>
            <span class="token literal-property property">name</span> <span class="token operator">:</span> <span class="token string">&quot;林黛玉小怼怼&quot;</span><span class="token punctuation">,</span>
            <span class="token literal-property property">sex</span> <span class="token operator">:</span> <span class="token string">&quot;女&quot;</span><span class="token punctuation">,</span>
            <span class="token literal-property property">age</span> <span class="token operator">:</span> <span class="token number">16</span> <span class="token punctuation">,</span>
            <span class="token literal-property property">weight</span> <span class="token operator">:</span> <span class="token string">&quot;50kg&quot;</span><span class="token punctuation">,</span>
            <span class="token literal-property property">height</span> <span class="token operator">:</span> <span class="token string">&quot;150cm&quot;</span><span class="token punctuation">,</span>
            <span class="token literal-property property">marry</span> <span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
            <span class="token literal-property property">husband</span> <span class="token operator">:</span> <span class="token punctuation">{</span>
                <span class="token literal-property property">name</span> <span class="token operator">:</span> <span class="token string">&quot;云牧&quot;</span><span class="token punctuation">,</span>
                <span class="token literal-property property">age</span> <span class="token operator">:</span> <span class="token number">18</span><span class="token punctuation">,</span>
                <span class="token literal-property property">hobby</span> <span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;唱歌&quot;</span> <span class="token punctuation">,</span> <span class="token string">&quot;看书&quot;</span> <span class="token punctuation">,</span> <span class="token string">&quot;吹箫&quot;</span><span class="token punctuation">]</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
 console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>lindaiyu<span class="token punctuation">.</span>husband<span class="token punctuation">.</span>hobby<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//吹箫</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h4 id="内置对象-节点对象"><a href="#内置对象-节点对象" class="header-anchor">#</a> 内置对象,节点对象</h4> <blockquote><p>内置对象(js提前帮你定义好的对象)</p> <p>节点对象(通过去获取的元素)</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>window<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//内置window对象,里面少读属性只读,大部分可读可写</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>document<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h4 id="函数对象"><a href="#函数对象" class="header-anchor">#</a> 函数对象</h4> <blockquote><p>函数是一段可以反复调用的代码块</p> <p>把一堆代码封装起来,不会立马去执行.</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">function</span> <span class="token function">fn</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&quot;大&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&quot;家&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&quot;好&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// 函数调用方式之一(主动调用)</span>
<span class="token function">fn</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="typeof-操作符"><a href="#typeof-操作符" class="header-anchor">#</a> typeof 操作符</h2> <blockquote><p>检测一个变量或数据的数据类型</p></blockquote> <p><strong>number类型</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//下面定义的变量都是number类型</span>
<span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token number">200</span><span class="token punctuation">;</span>       
<span class="token keyword">var</span> b <span class="token operator">=</span> <span class="token operator">-</span><span class="token number">123</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> c <span class="token operator">=</span> <span class="token number">123.456</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> d <span class="token operator">=</span> <span class="token number">.5e4</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> e <span class="token operator">=</span> <span class="token number">0xf0</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> f <span class="token operator">=</span> <span class="token number">016</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> g <span class="token operator">=</span> <span class="token number">Infinity</span><span class="token punctuation">;</span>       
<span class="token keyword">var</span> h <span class="token operator">=</span> <span class="token number">NaN</span><span class="token punctuation">;</span>

console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> a<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> b<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> d<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> e<span class="token punctuation">)</span><span class="token punctuation">;</span>      
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> f<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> g<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> h<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><blockquote><p><strong>JS中所有的数字都是number类型的</strong></p> <p>number类型的东西, 所有的数字(不分正负,整浮,大小,进制,),Infinity, NaN,不在细分为整形int、浮点型float这些乱七八糟的东西。</p></blockquote> <p><strong>string 字符串类型</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">var</span> str1 <span class="token operator">=</span> <span class="token string">&quot;您好啊&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> str2 <span class="token operator">=</span> <span class="token string">&quot;250&quot;</span><span class="token punctuation">;</span>   
<span class="token keyword">var</span> str3 <span class="token operator">=</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>      <span class="token comment">//空字符串，也是字符串</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> str1<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> str2<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> str3<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><strong>boolean类型</strong></p> <blockquote><p>boolean类型(布尔类型), 布尔类型只有两个值true,false,即真或假</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">var</span> bool <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>  
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>bool <span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> bool <span class="token punctuation">)</span><span class="token punctuation">;</span>      <span class="token comment">//boolean</span>

<span class="token comment">//注意:此时true,和false没有加引号,所以不是字符串</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>undefined 类型</strong></p> <blockquote><p>只let了一个变量，没有赋初值，它的默认值是undefined;</p> <p>这个undefined是自成一家，类型和值都是undefined。这种类型的值页只有一个。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">var</span> un<span class="token punctuation">;</span>   <span class="token comment">//我只定义了，没有赋初值，所以就是undefined，类型也是undefined</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>un<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> un<span class="token punctuation">)</span><span class="token punctuation">;</span>      <span class="token comment">//undefined</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//object</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//object</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//object</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> window<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//object  内置对象</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><strong>特殊 ：</strong></p> <blockquote><p>null 在使用typeof检测时 ，数据类型为Object</p> <p>历史原因造成的。1995年的 JavaScript 语言第一版，</p> <p>只设计了五种数据类型（对象、整数、浮点数、字符串和布尔值），没考虑<code>null</code>，只把它当作<code>object</code>的一种特殊值。</p> <p>后来<code>null</code>独立出来，作为一种单独的数据类型，为了兼容以前的代码，<code>typeof null</code>返回<code>object</code>就没法改变了。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//object类型  但是是null类型</span>
<span class="token comment">//所以 建议 在定义一个未知的对象时，先将其定义为 null</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">typeof</span> <span class="token keyword">function</span> <span class="token function">a</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token comment">//function 更好区分普通对象和函数对象</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h2 id="赋值和取值"><a href="#赋值和取值" class="header-anchor">#</a> 赋值和取值</h2> <p><strong>赋值</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span> <span class="token comment">//赋值 --&gt; 10赋值给a变量</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>取值</strong></p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> b <span class="token operator">=</span> a <span class="token operator">*</span> <span class="token number">10</span><span class="token punctuation">;</span><span class="token comment">//取值 --&gt; a变量的值取出来乘以10 赋值给b变量</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>数组和对象数据的取值和赋值</strong></p> <ul><li><strong>数组</strong></li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">10</span> <span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//取值</span>
arr<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">100</span><span class="token comment">//赋值</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span>


 <span class="token keyword">let</span> a <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
 <span class="token keyword">let</span> b <span class="token operator">=</span> a <span class="token operator">*</span> <span class="token number">10</span><span class="token punctuation">;</span>
 <span class="token keyword">let</span> arr1 <span class="token operator">=</span> <span class="token punctuation">[</span>a <span class="token punctuation">,</span> b<span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token comment">//取值  本来要存数据,但是是变量,要找变量所对应的数据</span>
 console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr1<span class="token punctuation">)</span><span class="token punctuation">;</span> 

<span class="token comment">//区分开</span>
 <span class="token keyword">let</span> arr2 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">&quot;a&quot;</span> <span class="token punctuation">,</span> <span class="token string">&quot;b&quot;</span><span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token comment">// 此时a b 都是字符串数据,直接存储.</span>
 console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr2<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><p>如果直接在数组内写入a变量,但是a没有被定义出来</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 报错 --&gt; 因为a没有被定义,找不到没有变量a; 区分undefined是一种数据类型,不是报错</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li><strong>对象</strong></li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">let</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token literal-property property">x</span> <span class="token operator">:</span> <span class="token number">66</span> <span class="token punctuation">,</span> <span class="token literal-property property">y</span> <span class="token operator">:</span> <span class="token number">99</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span>x<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//取值</span>

obj<span class="token punctuation">.</span>x <span class="token operator">=</span> <span class="token number">200</span><span class="token punctuation">;</span><span class="token comment">//重新赋值</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>读取操作对象属性 除了 . 操作之外， <strong>对象还可以通过 [] 取值</strong></p> <p><strong>注意</strong></p> <blockquote><p>如果使用方括号，属性名必须放在引号里面，否则会当成变量来处理</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj<span class="token punctuation">[</span><span class="token string">&quot;x&quot;</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span>x<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">//如果使用.操作符   x 就是 字符串</span>
<span class="token comment">//如果使用方括号运算符 不使用引号    x就是变量</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><strong>使用场景</strong></p> <blockquote><p>方括号可以代替点操作符  但如果要访问例数值等不符合标准的属性名，必须使用[]去进行操作</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code>console<span class="token punctuation">[</span><span class="token string">&quot;log&quot;</span><span class="token punctuation">]</span><span class="token punctuation">(</span><span class="token string">&quot;如果云层是天空的一封信&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><img src="https://s1.ax1x.com/2020/09/10/wJj82V.png" alt="wJj82V.png"></p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/./guide/notes/js/01-认识javaScript.html" class="prev">
        01-认识javaScript
      </a></span> <span class="next"><a href="/./guide/notes/js/03-基础dom操作.html">
        03-基础dom操作
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----><div class="reco-bgm-panel" data-v-b1d3339e><audio id="bgm" src="https://www.ytmp3.cn/down/75475.mp3" data-v-b1d3339e></audio> <div class="reco-float-box" style="bottom:30px;z-index:999999;display:none;" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><img src="https://p1.music.126.net/qTSIZ27qiFvRoKj-P30BiA==/109951165895951287.jpg?param=200y200" data-v-b1d3339e></div> <div class="reco-bgm-box" style="left:10px;bottom:10px;z-index:999999;" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><div class="reco-bgm-cover" style="background-image:url(https://p1.music.126.net/qTSIZ27qiFvRoKj-P30BiA==/109951165895951287.jpg?param=200y200);" data-v-b1d3339e><div class="mini-operation" style="display:none;" data-v-b1d3339e><i class="reco-bgm reco-bgm-pause" style="display:none;" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-play" style="display:none;" data-v-b1d3339e></i></div> <div class="falut-message" style="display:none;" data-v-b1d3339e>
          播放失败
        </div></div> <div class="reco-bgm-info" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><div class="info-box" data-v-b1d3339e><i class="reco-bgm reco-bgm-music music" data-v-b1d3339e></i>花花公子</div> <div class="info-box" data-v-b1d3339e><i class="reco-bgm reco-bgm-artist" data-v-b1d3339e></i>马思唯/step.jad</div> <div class="reco-bgm-progress" data-v-b1d3339e><div class="progress-bar" data-v-b1d3339e><div class="bar" data-v-b1d3339e></div></div></div> <div class="reco-bgm-operation" data-v-b1d3339e><i class="reco-bgm reco-bgm-last last" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-pause pause" style="display:none;" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-play play" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-next next" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-volume1 volume" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-mute mute" style="display:none;" data-v-b1d3339e></i> <div class="volume-bar" data-v-b1d3339e><div class="bar" data-v-b1d3339e></div></div></div></div> <div class="reco-bgm-left-box" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><i class="reco-bgm reco-bgm-left" data-v-b1d3339e></i></div></div></div></div></div>
    <script src="./assets/js/app.7878252f.js" defer></script><script src="./assets/js/2.877879cc.js" defer></script><script src="./assets/js/41.23b0f26d.js" defer></script>
  </body>
</html>
